home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
PC World Komputer 2010 April
/
PCWorld0410.iso
/
pluginy Firefox
/
53696
/
53696.xpi
/
chrome
/
content
/
locator.js
< prev
next >
Wrap
Text File
|
2009-12-18
|
12KB
|
451 lines
String.prototype.ltrim = function String$ltrim() { var re = /\s*((\S+\s*)*)/; return this.replace(re, "$1"); }
String.prototype.rtrim = function String$rtrim() { var re = /((\s*\S+)*)\s*/; return this.replace(re, "$1"); }
String.prototype.trim = function String$trim() { return this.ltrim(this.rtrim()); }
var SPACING = 200,
FS_DESKTOP = 0,
FS_PERSONAL = 1,
FS_PHOTOS = 2,
FS_MUSIC = 3,
FS_VIDEOS = 4,
FS_DOCS = 5,
FS_BOOKMARKS = 6,
FS_SITES = 7;
var EMPTY_GUID = "00000000-0000-0000-0000-000000000000",
DESKTOP_ASSET_ID = "10000001-1001-1001-1001-100000000001",
SYSTEM_ASSET_ID_PERSONAL = "00000000-0000-0000-0001-000000000000",
SYSTEM_ASSET_ID_PHOTOS = "00000000-0000-0001-0001-000000000000",
SYSTEM_ASSET_ID_MUSIC = "00000000-0000-0001-0002-000000000000",
SYSTEM_ASSET_ID_VIDEOS = "00000000-0000-0001-0003-000000000000",
SYSTEM_ASSET_ID_DOCS = "00000000-0000-0001-0004-000000000000",
SYSTEM_ASSET_ID_BOOKMARKS = "00000000-0000-0001-0005-000000000000";
var prompt = null;
var glideSession = null;
var invokeService = null;
var ENDPOINT_FS = null;
var sync = false;
var columns = null;
var currentColumn = null;
var currentItem = null;
var newId = null;
var loadIndicator = null;
function hideLoadIndicator() {
var i = document.getElementById("column_load_indicator");
if (i)
document.getElementById("locator_columns").removeChild(i);
}
function showLoadIndicator() {
var i = document.getElementById("column_load_indicator");
if (i)
return;
var lc = document.getElementById("locator_columns");
lc.appendChild(loadIndicator);
lc.boxObject.QueryInterface(Components.interfaces.nsIScrollBoxObject).ensureElementIsVisible(loadIndicator);
}
function renderColumn(col) {
var box = document.createElement("listbox");
box.id = "locator_column_" + col.index;
box.setAttribute("rel", col.index);
box.addEventListener("select", function() { itemSelected(this); }, false);
var item = null;
var title = "";
var listitem = null;
var selectedIndex = -1;
for (var i = 0; i < col.items.length; i++) {
item = col.items[i];
listitem = document.createElement("listitem");//box.appendItem(item.title, item.assetid);
listitem.setAttribute("label", item.title);
listitem.setAttribute("value", item.assetid);
listitem.setAttribute("class", "listitem-iconic");
if (item.syncEnabled)
listitem.setAttribute("label", item.title + " (sync enabled)");
if (item.syncEnabled)
listitem.setAttribute("image", "chrome://glide/content/images/icon_sync.png");
if (newId != null && item.assetId != null && newId.toLowerCase() == item.assetId.toLowerCase()) {
selectedIndex = i;
}
box.appendChild(listitem);
}
var lc = document.getElementById("locator_columns");
lc.appendChild(box);
lc.boxObject.QueryInterface(Components.interfaces.nsIScrollBoxObject).ensureElementIsVisible(box);
if (selectedIndex > 0)
{
box.selectedIndex = selectedIndex;
box.focus();
}
newId = null;
}
function removeColumnsAfter(index) {
var ch = document.getElementById("locator_columns");
var na = new Array();
for (var i = 0; i < columns.length; i++) {
if (i > index)
ch.removeChild(document.getElementById("locator_column_" + i));
else
na.push(columns[i]);
}
columns = na;
}
function itemSelected(who) {
document.documentElement.getButton("accept").disabled = false;
document.documentElement.getButton("extra2").disabled = false;
currentColumn = columns[who.getAttribute("rel")];
currentItem = currentColumn.items[who.selectedIndex];
if (!currentItem.loadNext)
return;
removeColumnsAfter(currentColumn.index);
showLoadIndicator();
currentItem.loadNext(currentItem);
}
function addColumn(col) {
renderColumn(col);
columns.push(col);
}
function makeAssetColumn(data) {
if (null == data) {
hideLoadIndicator();
return;
}
if (!data.success) {
hideLoadIndicator();
alert(data.message);
return;
}
var items = new Array();
var item = null;
var results = data.items;
var r = null;
for (var i = 0; i < results.length; i++) {
r = results[i];
item = {
assetId: r.assetId,
title: r.title,
loadNext: null,
enableNewFolder: true,
selectable: true,
syncEnabled: r.syncEnabled
};
if (currentItem.subtype)
item.subtype = currentItem.subtype;
if ("Container" == r.assetClass || "Conversation" == r.assetClass || "Webmail" == r.assetClass || "Chat" == r.assetClass) {
if ("Mail" == r.metadataClass)
item.loadNext = function(w) { loadEmailBox(false, w.assetId); };
else
item.loadNext = function(w) { loadAssetLocation(w); };
}
else if ("Project" == r.assetClass) {
item.loadNext = function(w) { loadGroupBox(false, w.assetId); };
}
items.push(item);
}
hideLoadIndicator();
document.documentElement.getButton("accept").disabled = !currentItem.selectable;
document.documentElement.getButton("extra2").disabled = !currentItem.enableNewFolder;
addColumn({
index: currentColumn.index + 1,
items: items
});
}
function loadAssetLocation(who) {
invokeService(ENDPOINT_FS, "getfolders", false, { token: glideSession.token, id: who.assetId }, makeAssetColumn);
}
function loadGroupBox(inbox, parentId) {
var data = {
token: glideSession.token,
type: inbox ? "inbox" : "outbox"
};
if (parentId)
data.parentId = parentId;
invokeService(ENDPOINT_FS, "getgroupbox", false, data, makeAssetColumn);
}
function loadGroups() {
hideLoadIndicator();
addColumn({
index: currentColumn.index + 1,
items: [{ title: "Inbox", assetId: null, loadNext: function() { loadGroupBox(true); }, enableNewFolder: false, selectable: false }, { title: "Outbox", assetId: null, loadNext: function() { loadGroupBox(false); }, enableNewFolder: false, selectable: false}]
});
}
function loadEngageBox(sent) {
invokeService(ENDPOINT_FS, "getengagebox", false, { token: glideSession.token, type: sent ? "outbox" : "inbox" }, makeAssetColumn);
}
function loadEngageGroups() {
hideLoadIndicator();
addColumn({
index: currentColumn.index + 1,
items: [{ title: "Inbox", assetId: null, loadNext: function() { loadEngageBox(true); }, enableNewFolder: false, selectable: false }, { title: "Outbox", assetId: null, loadNext: function() { GlideLocatorColumn_loadEngageBox(false); }, enableNewFolder: false, selectable: false}]
});
}
function loadEmailBox(sent, folderId) {
var data = {
token: glideSession.token,
type: sent ? "sent" : "draft"
};
if (folderId)
data.folderId = folderId;
invokeService(ENDPOINT_FS, "getemailbox", false, data, makeAssetColumn);
}
function loadEmails() {
hideLoadIndicator();
addColumn({
index: currentColumn.index + 1,
items: [{ title: "Last 200 Sent", assetId: null, loadNext: function() { loadEmailBox(true); }, enableNewFolder: false, selectable: false }, { title: "Drafts", assetId: null, loadNext: function() { loadEmailBox(false); }, enableNewFolder: false, selectable: false}]
});
}
function loadMeetingBox(inbox) {
invokeService(ENDPOINT_FS, "getmeetingbox", false, { token: glideSession.token, type: inbox ? "inbox" : "outbox" }, makeAssetColumn);
}
function loadMeetings() {
hideLoadIndicator();
addColumn({
index: currentColumn.index + 1,
items: [{ title: "Inbox", assetId: null, loadNext: function() { loadMeetingBox(true); }, enableNewFolder: false, selectable: false }, { title: "Outbox", assetId: null, loadNext: function() { loadMeetingBox(false); }, enableNewFolder: false, selectable: false}]
});
}
function loadRootLocation(id) {
if (FS_DESKTOP == id) {
invokeService(ENDPOINT_FS, "getdesktopfolders", false, { token: glideSession.token }, makeAssetColumn);
return;
}
var guid = SYSTEM_ASSET_ID_PERSONAL;
switch (id) {
case FS_PERSONAL: break;
case FS_PHOTOS: guid = SYSTEM_ASSET_ID_PHOTOS; break;
case FS_MUSIC: guid = SYSTEM_ASSET_ID_MUSIC; break;
case FS_VIDEOS: guid = SYSTEM_ASSET_ID_VIDEOS; break;
case FS_DOCS: guid = SYSTEM_ASSET_ID_DOCS; break;
case FS_BOOKMARKS: guid = SYSTEM_ASSET_ID_BOOKMARKS; break;
default: return;
}
invokeService(ENDPOINT_FS, "getrootfolder", false, { token: glideSession.token, id: guid }, makeAssetColumn);
}
function newFolder() {
var name = { value: "" };
if (!prompt.prompt(null, "New Folder", "Please enter the name of the new folder:", name, "", {}))
return;
name.value = name.value.trim();
removeColumnsAfter(currentColumn.index);
showLoadIndicator();
document.documentElement.getButton("accept").disabled = true;
document.documentElement.getButton("extra2").disabled = true;
var data = {
token: glideSession.token,
name: name.value,
sync: sync,
parentId: currentItem.assetId,
};
if (currentItem.subtype)
data.subtype = currentItem.subtype;
invokeService(ENDPOINT_FS, "createfolder", false, data, function(d) {
if (d.success) {
newId = d.value;
currentItem.loadNext(currentItem);
} else {
hideLoadIndicator();
alert(d.message);
}
});
}
function glideLocatorDialog_Load() {
prompt = Components.classes["@mozilla.org/embedcomp/prompt-service;1"].getService(Components.interfaces.nsIPromptService);
glideSession = window.arguments[0].inn.glideSession;
invokeService = window.arguments[0].inn.invokeService;
ENDPOINT_FS = window.arguments[0].inn.ENDPOINT_FS;
sync = window.arguments[0].inn.sync;
columns = new Array();
document.getElementById("glide-locator-instruction").textContent = "Please choose the " + (sync ? "Sync" : "") + " destination where you would like to save this item:";
loadIndicator = document.getElementById("column_load_indicator");
document.getElementById("locator_columns").removeChild(loadIndicator);
var c = {
index: 0,
items: new Array()
};
c.items.push({
title: "Desktop",
assetId: DESKTOP_ASSET_ID,
loadNext: function() { loadRootLocation(FS_DESKTOP); },
enableNewFolder: true,
selectable: !sync,
subtype: "Personal"
});
c.items.push({
title: glideSession.fullName,
assetId: null,
loadNext: function() { loadRootLocation(FS_PERSONAL); },
enableNewFolder: true,
selectable: !sync,
subtype: "Personal"
});
c.items.push({
title: "Photos",
assetId: null,
loadNext: function() { loadRootLocation(FS_PHOTOS); },
enableNewFolder: true,
selectable: !sync,
subtype: "Image"
});
c.items.push({
title: "Music",
assetId: null,
loadNext: function() { loadRootLocation(FS_MUSIC); },
enableNewFolder: true,
selectable: !sync,
subtype: "Audio"
});
c.items.push({
title: "Videos",
assetId: null,
loadNext: function() { loadRootLocation(FS_VIDEOS); },
enableNewFolder: true,
selectable: !sync,
subtype: "Video"
});
c.items.push({
title: "Documents",
assetId: null,
loadNext: function() { loadRootLocation(FS_DOCS); },
enableNewFolder: true,
selectable: !sync,
subtype: "Document"
});
c.items.push({
title: "Bookmarks",
assetId: null,
loadNext: function() { loadRootLocation(FS_BOOKMARKS); },
enableNewFolder: true,
selectable: !sync,
subtype: "Url"
});
c.items.push({
title: "Engage Discussions",
assetId: null,
loadNext: function() { loadEngageGroups(); },
enableNewFolder: false,
selectable: false
});
c.items.push({
title: "Emails",
assetId: null,
loadNext: function() { loadEmails(); },
enableNewFolder: false,
selectable: false
});
c.items.push({
title: "Groups",
assetId: null,
loadNext: function() { loadGroups(); },
enableNewFolder: false,
selectable: false
});
c.items.push({
title: "Meetings",
assetId: null,
loadNext: function() { loadMeetings(); },
enableNewFolder: false,
selectable: false
});
addColumn(c);
document.documentElement.getButton("accept").disabled = true;
document.documentElement.getButton("extra2").disabled = true;
}
function glideLocatorDialog_Accept() {
window.arguments[0].out = { value: currentItem.assetId };
return true;
}